-
Notifications
You must be signed in to change notification settings - Fork 19.6k
[OpenVINO backend] Support numpy.logaddexp #21522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @samthakur587, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
I've added support for the logaddexp function to the OpenVINO backend. This change enables the backend to correctly handle operations involving logaddexp, which was previously unsupported, by providing a robust and numerically stable implementation.
Highlights
- OpenVINO Backend Extension: I've implemented the logaddexp function within the keras/src/backend/openvino/numpy.py file. This involves using OpenVINO operations (maximum, subtract, abs, negative, exp, log1p, add) to provide a numerically stable computation of log(exp(x1) + exp(x2)).
- Test Suite Integration: I've removed logaddexp from the excluded_concrete_tests.txt file for both NumpyDtypeTest and NumpyOneInputOpsCorrectnessTest. This indicates that the logaddexp operation is now expected to pass its corresponding tests in the OpenVINO backend.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request adds support for the logaddexp
operation to the OpenVINO backend, which is a great addition. The implementation correctly uses a numerically stable formula. I have one suggestion to improve the code's readability by making it more concise.
keras/src/backend/openvino/numpy.py
Outdated
max_val = ov_opset.maximum(x1, x2).output(0) | ||
abs_diff = ov_opset.abs(ov_opset.subtract(x1, x2).output(0)).output(0) | ||
neg_abs_diff = ov_opset.negative(abs_diff).output(0) | ||
exp_neg_abs = ov_opset.exp(neg_abs_diff).output(0) | ||
log1p_exp = ov_opset.log1p(exp_neg_abs).output(0) | ||
result = ov_opset.add(max_val, log1p_exp).output(0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation can be made more concise and readable by removing the redundant .output(0)
calls. The OpenVINO ops can directly accept Node
objects as inputs, and the .output(0)
is only necessary when you need to explicitly get the output tensor, for example, before returning it or wrapping it in OpenVINOKerasTensor
.
max_val = ov_opset.maximum(x1, x2).output(0) | |
abs_diff = ov_opset.abs(ov_opset.subtract(x1, x2).output(0)).output(0) | |
neg_abs_diff = ov_opset.negative(abs_diff).output(0) | |
exp_neg_abs = ov_opset.exp(neg_abs_diff).output(0) | |
log1p_exp = ov_opset.log1p(exp_neg_abs).output(0) | |
result = ov_opset.add(max_val, log1p_exp).output(0) | |
max_val = ov_opset.maximum(x1, x2) | |
abs_diff = ov_opset.abs(ov_opset.subtract(x1, x2)) | |
neg_abs_diff = ov_opset.negative(abs_diff) | |
exp_neg_abs = ov_opset.exp(neg_abs_diff) | |
log1p_exp = ov_opset.log1p(exp_neg_abs) | |
result = ov_opset.add(max_val, log1p_exp).output(0) |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #21522 +/- ##
=======================================
Coverage 82.73% 82.74%
=======================================
Files 567 567
Lines 56464 56497 +33
Branches 8825 8830 +5
=======================================
+ Hits 46718 46749 +31
Misses 7582 7582
- Partials 2164 2166 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
@samthakur587 , can you rebase to merge changes to excluded_concrete_tests.txt? Then I can merge. Thanks! |
@hertschuh done ! |
details: in this pr i have added logaddexp support for openvino backend
cc, @gbaned could you please review ?